home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / LIBRARY / PAS_0793 / FSTLCSTR.PAS < prev    next >
Pascal/Delphi Source File  |  1993-08-01  |  2KB  |  49 lines

  1. {─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
  2. Msg  : 253 of 292
  3. From : Todd Holmes                         1:152/5.0            29 Jun 93  23:55
  4. To   : Dj Murdoch
  5. Subj : A Faster LoadCstr
  6. ────────────────────────────────────────────────────────────────────────────────
  7.         Heres a slightly faster LoadCstr. I'ld like you to note my use of
  8. type conversions to (quickly??) INC/DEC var of type pointer.
  9.  
  10. Warning, this function by-passes standard pascals strict type checking.
  11.  in other words, the lack (or addtion) of a simple little '^' (carrot)
  12.  can send your program off to ... well, just about anywhere :) and yes,
  13.  I do speak from experiance.}
  14.  
  15.  
  16. Function LoadCStr(Var S:TStream): PChar; {Ver .03}
  17. {Implemented quick type conversion to directly INC/DEC variables of
  18.  Type Pointer. If you have the Unit: CSTR ver .02, then replace the old
  19.  LoadCstr with this new Funtion}
  20. var
  21.  Buff_Head:PChar;   {Head: as in read/write head, to access the resizable
  22.                      Array}
  23. begin
  24.   Buff_Head := PChar(Longint(CStrBuff)-1); {CStrBuff is a resizable Array}
  25.     {Buff_Head now points to 1 byte before CStrBuff}
  26.   Repeat                        {Scan for end of string, (nul term char: #0)}
  27.     IncP(Buff_Head));           {Heres how to increase a Pointer Var}
  28.     S.Read(Buff_Head^,1);       {Read straight to buffer}
  29.   Until (Buff_Head^ = #0) or
  30.         (Longint(Buff_Head) = MaxStrLen) or (S.Status <> StOk);
  31.   If Longint(Buff_Head) = MaxStrLen then
  32.      Buff_Head^ := #0;          {Truncate to MaxStrLen}
  33.   LoadCstr := StrNew(CStrBuff); {Strings Unit: Makes copy of String
  34.                                  in CstrBuff}
  35. end; {LoadCstr}
  36.  
  37. {in addtion are two Procedures to Directly INC/DEC var of type pointer, the
  38. main purpose for INC/DEC pointers, is for Indexing resizable arrays,
  39. (see Unit CStr) something that standard pascal is missing.}
  40.  
  41. Procedure IncP(Var P:Pointer);
  42. begin
  43.  Inc(Longint(P));
  44. end;
  45.  
  46. Procedure DecP(Var P:Pointer);
  47. begin
  48.  Dec(Longint(P)):
  49. end;